'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	const collection = db.collection(event.t)
	const docList = await collection.where({
		_id: event.data._id
	}).get()
	if (!docList.data || docList.data.length === 0) {
		return {
			status: -1,
			msg: event.t + '表内没有对应数据哦',
			docList: docList
		}
	}
	delete event.data._id;
	const res = await collection.doc(docList.data[0]._id).update(event.data);
	if (res.updated === 1) {
		let result = Object.assign({}, {
			_id: docList.data[0]._id
		}, event.data)
		return {
			status: 200,
			msg: '修改成功'
		}
	} else {
		return {
			status: -1,
			msg: '修改失败!',
			res: res
		}
	}
};
